<template>
	<view class="content" :style="{background: `url(${imgPath}storage/home/home_bg.png)`}">
		<view class="box">
			<view class="meritsrank"
				:style="{background: `url(${imgPath}storage/home/merit_bg.png) no-repeat;background-size: 100% 100%;`}">
				<view class="title">
					<u--image :showLoading="true" :src="imgPath + 'storage/home/merit.png'" width="504rpx"
						height="184rpx"></u--image>
				</view>
				<view class="nav">
					<view class="left" :class="(form.type==1)?'active':''" @click="switchNav(1)">
						<text>功德金额榜</text>
						<view class="active-line"></view>
					</view>
					<view class="right" :class="(form.type==2)?'active':''" @click="switchNav(2)">
						<text>功德数量榜</text>
						<view class="active-line"></view>
					</view>
				</view>
				<view class="my">
					<view class="left">
						<view class="left-title">
							我的 功德
						</view>
						<view class="avatar">
							<u--image :showLoading="true" :src="userInfo.avatar" shape="circle" width="60rpx"
								height="60rpx"></u--image>
						</view>
						<view class="name">
							{{userInfo.nick || '-'}}
						</view>
					</view>
					<view class="right">
						<view class="num">
							{{userInfo.merit_num || '-'}}
						</view>
						<view class="money">
							¥{{userInfo.merit_amount || '0'}}
						</view>
					</view>
				</view>
				<scroll-view class="list" scroll-y>
					<view class="item" v-for="(item,index) in meritlist">
						<view class="left">
							<view class="index">
								<u--image v-if="index==0" :showLoading="true" :src="imgPath + 'storage/home/no_one.png'"
									width="50rpx" height="64rpx"></u--image>
								<u--image v-if="index==1" :showLoading="true" :src="imgPath + 'storage/home/no_two.png'"
									width="50rpx" height="64rpx"></u--image>
								<u--image v-if="index==2" :showLoading="true"
									:src="imgPath + 'storage/home/no_three.png'" width="50rpx"
									height="64rpx"></u--image>
								<text v-if="index>2">{{index+1}}</text>
							</view>
							<view class="avatar">
								<u--image :showLoading="true" shape="circle" :src="item.avatar" width="60rpx"
									height="60rpx"></u--image>
							</view>
							<view class="name">
								{{item.nick}}
							</view>
						</view>
						<view class="right">
							<view class="money" v-if="form.type == 1">
								¥{{item.merit_amount}}
							</view>
							<view class="num" v-if="form.type == 2">
								{{userInfo.merit_num}}
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="pary" @click="goPary">
			我要商品
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imgPath: this.$store.state.user.baseURL,
				form: {
					type: 1
				},
				meritlist: [],
				userInfo: {}
			}
		},
		onLoad() {
			this.getMeritList()
		},
		methods: {
			switchNav(type) {
				console.log(type);
				this.form.type = type
				this.getMeritList()
			},
			getMeritList() {
				this.$api.meritList(this.form).then(res => {
					this.meritlist = res.data.list
					this.userInfo = res.data.info
				})
			},
			goPary() {
				uni.switchTab({
					url: '/pages/templelist/templelist'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		min-height: 100vh;
		z-index: -1;
	}

	.box {
		padding: 0 16rpx;
		padding-top: 20rpx;
	}

	.meritsrank {
		height: calc(100vh - 180rpx);
		box-sizing: border-box;
		padding: 108rpx 74rpx 110rpx 74rpx;

		.title {
			display: flex;
			justify-content: center;
		}

		.nav {
			margin-top: 8rpx;
			height: 100rpx;
			background: #976A3F;
			border-radius: 20rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-around;

			.left,
			.right {
				display: flex;
				flex-direction: column;
				align-items: center;

				text {
					padding-top: 28rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 600;
					font-size: 30rpx;
					color: #C6AD96;
					font-style: normal;
				}
			}

			.active {
				text {
					color: #FFFFFF !important;
				}

				.active-line {
					margin-top: 10rpx;
					width: 60rpx;
					height: 8rpx;
					background: #FFFFFF;
					border-radius: 4rpx;
				}
			}
		}

		.my {
			margin-top: 16rpx;
			height: 108rpx;
			background: #F4D5A8;
			border-radius: 20rpx;
			display: flex;
			justify-content: space-between;
			padding: 0 30rpx 0 20rpx;

			.left {
				display: flex;
				align-items: center;

				.left-title {
					width: 40rpx;
					height: 48rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 600;
					font-size: 20rpx;
					color: #D02222;
					line-height: 24rpx;
					text-align: left;
					font-style: normal;
				}

				.avatar {
					padding: 0 20rpx;
				}

				.name {
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #111111;
					line-height: 40rpx;
					text-align: left;
					font-style: normal;
				}
			}

			.right {
				display: flex;
				align-items: center;
				font-family: PingFangSC, PingFang SC;
				font-weight: 600;
				font-size: 28rpx;
				color: #D06122;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;

				.num {
					padding-right: 30rpx;
				}

				.money {}
			}
		}

		.list {
			// background-color: #D02222;
			margin-top: 16rpx;
			// flex: 1;
			height: calc(100vh - 800rpx);

			.item {
				padding: 24rpx 10rpx;
				display: flex;
				justify-content: space-between;

				.left {
					display: flex;
					align-items: center;

					.index {
						width: 50rpx;
						height: 64rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #111111;
						line-height: 64rpx;
						text-align: center;
						font-style: normal;
					}

					.name {
						font-family: PingFangSC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #111111;
						line-height: 40rpx;
						text-align: left;
						font-style: normal;
					}

					.avatar {
						padding: 0 20rpx;
					}
				}

				.right {
					.money {
						font-family: PingFangSC, PingFang SC;
						font-weight: 600;
						font-size: 28rpx;
						color: #D06122;
						line-height: 40rpx;
						text-align: left;
						font-style: normal;
					}

					.num {
						font-family: PingFangSC, PingFang SC;
						font-weight: 600;
						font-size: 28rpx;
						color: #D06122;
						line-height: 40rpx;
						text-align: left;
						font-style: normal;
					}
				}
			}
		}
	}

	.pary {
		position: fixed;
		bottom: 60rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 630rpx;
		height: 84rpx;
		background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
		border-radius: 42rpx;
		font-family: PingFangSC, PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #FFFFFF;
		line-height: 84rpx;
		text-align: center;
		font-style: normal;
	}
</style>